import java.util.Scanner;

public class MethodHomework {

    //1.使用函数求最大值
    //创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
    //要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算

    public static int max2(int a, int b) {
        int ret = 0;
        if (a > b) {
            ret = a;
        } else if (a < b) {
            ret = b;
        } else {
            System.out.println("相等");
        }
        return ret;
    }

    public static int max3(int a, int b, int c) {
        int tmp = max2(a, b);
        if (tmp > c) {
            ;
        } else if (tmp < c) {
            tmp = c;
        } else {
            System.out.println("相等");
        }
        return tmp;

    }

    //2.求 N 的阶乘
    public static int factorial(int n) {
        if (n == 1 || n == 0) {
            return 1;
        }
        int ret = n * factorial(n - 1);
        return ret;
    }

    //3.求阶乘和
    //求1！+2！+3！+4！+........+n!的和

    public static int sumFactorial(int n) {
        int sum = 0;
        for (int i = n; i >= 1; i--) {
            int tmp = factorial(i);
            sum += tmp;
        }
        return sum;
    }

    //4.斐波那契数列
    //求斐波那契数列的第n项。(迭代实现)
    public static int fib(int n) {
        int last1 = 1;
        int last2 = 1;
        int cur = 0;
        for (int i = 3; i <= n; i++) {
            cur = last1 + last2;
            last2 = last1;
            last1 = cur;
        }
        return cur;
    }

    //5.求和的重载
    // 在同一个类中,分别定义求两个整数的方法 和 三个小数之和的方法。 并执行代码，求出结果
    public static int sum(int a, int b) {
        return a + b;
    }

    public static double sum(double a, double b, double c) {
        return a + b + c;
    }

    //6.求最大值方法的重载
    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
    public static int max(int a, int b) {
        int ret = a;
        if (a > b) {
            ;
        } else if (a < b) {
            ret = b;
        } else {
            System.out.println("相等");
        }
        // int ret = a > b ? a : b;
        return ret;
    }

    public static double max(double a, double b) {
        double ret = a;

        if (a > b) {
            ;
        } else if (a < b) {
            ret = b;
        } else {
            System.out.println("相等");
        }
        return ret;
    }

    public static double max(double a, double b, double c) {
        double tmp = max(a,b);

        double ret = max(tmp,c);

        return ret;

    }

    //8.汉诺塔问题实现
    //a存放起始柱，b存放辅助柱、c存放目标柱
    public static void hanoi(int num, char a, char b, char c){
        if (num == 1) {
            System.out.println("第" + num + "个圆盘从" + a + " -> " + c);
        }else{
            hanoi(num - 1, a, c, b);//借助c把第 num 个以外的圆盘从a移动到b
            System.out.println("第" + num + "个圆盘从" + a + " -> " + c);//把第num个从a移动到c
            hanoi(num - 1, b, a, c);//借助a把第 num 个以外的圆盘从b移动到c
        }
    }


    public static void main(String[] args) {
        System.out.println("第一题" + max3(2, 50, 20));

        System.out.println("第二题" + factorial(5));

        System.out.println("第三题" + sumFactorial(3));

        System.out.println("第四题" + fib(3));

        System.out.println("第五题" + sum(2, 3) + "," + sum(1.2, 2.1, 2.2));

        System.out.println("第六题" + "2和20的最大值是" + max(2, 20) + "\n" +
                "1.1和77.77的最大值是" + max(1.1, 77.77) + "\n" +
                "15.13、12.12、4.20的最大值是" + max(15.13, 12.12, 4.20));
        System.out.println("第七题" + factorial(6));

        Scanner in = new Scanner(System.in);
        System.out.println("请输入圆盘的数量");
        int num = in.nextInt();
        hanoi(num, 'A', 'B', 'C');//起始柱、辅助柱、目标柱默认为A、B、C

    }
}
